package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/03 23:26
 **/
public class Day19_4_Num14_LongestCommonPrefix {
    class Solution {
        public String longestCommonPrefix(String[] strs) {
            if(strs.length == 0) return null;
            if(strs.length == 1) return strs[0];

            String res = "";
            for(int i = 0;i < strs[0].length();i++){
                char a = strs[0].charAt(i);
                for(String s : strs){
                    if(i >= s.length() || a != s.charAt(i)) return res;
                }
                res += a;
            }
            return res;
        }
    }
}